<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
    <script src="https://cdn.staticfile.org/vue-router/2.7.0/vue-router.min.js"></script>
    <style>
        #app {
            text-align: center;
        }

        .container {
            background-color: #73ffd6;
            margin-top: 20px;
            height: 300px;
        }

        .son {
            margin-top: 30px;
        }
    </style>
</head>


<body>

    <div id="app">
        <router-link :to="{name:'route1'}">首页</router-link>
        <router-link :to="{name:'route2'}">列表</router-link>
        <div class="container">
            <router-view></router-view>
        </div>
    </div>
    <template id="tmpl">
        <div>
            <h3>列表内容</h3>
            <router-link :to="{name:'route3'}">登录</router-link>
            <router-link :to="{name:'route4'}">注册</router-link>
            <div class="son">
                <router-view></router-view>
            </div>
        </div>
    </template>
    <script>
        const home = {
            template: '<div><h3>首页内容</h3></div>'
        }
        const list = {
            template: '#tmpl'
        }
        const login = {
            template: '<div><h3>登录内容</h3></div>'
        }
        const register = {
            template: '<div><h3>注册页面内容</h3></div>'
        }
        const router = new VueRouter({
            routes: [
                {
                    path: '/',
                    redirect: '/home'
                },
                {
                    path: '/home',
                    name: 'route1',
                    component: home
                },
                {
                    path: '/list',
                    name: "route2",
                    component: list,
                    children: [
                        {
                            path: '/list/login',
                            name: 'route3',
                            component: login
                        },
                        {
                            path: '/list/register',
                            name: 'route4',
                            component: register
                        }
                    ]
                },

            ]
        })
        const app = new Vue({
            el: "#app",
            data() {
                return {

                }
            },
            router: router
        })
    </script>
</body>

</html>
